﻿using System.ComponentModel;
using System.Windows.Input;
using KinonekoSoftware.Foundation;

namespace KinonekoSoftware.Platform.Controls
{
    public abstract class TabbedWindow : ForestWindow
    {
        protected TabbedWindow()
        {
        }

        protected override async Task<bool> CanClose()
        {
            var target = ViewModel<TabbedShell>();

            if (target.ShouldDirectExit)
            {
                target.Stop();
                return true;
            }
            
            if (!await ViewModelBase.DangerOperation(
                                                     TextSR.Dialog_Framework_DangerOperation,
                                                     TextSR.Dialog_Framework_CloseWindow))
            {
                return false;
            }
            
            target.Stop();
            return true;
        }
        
        
        internal sealed override void OnLoadedInternal()
        {
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            ViewModel<TabbedShell>().KeyDown(e);
            base.OnKeyDown(e);
        }

        protected override void OnKeyUp(KeyEventArgs e)
        {
            ViewModel<TabbedShell>().KeyUp(e);
            base.OnKeyUp(e);
        }
        
        

        internal override void OnUnloadedInternal()
        {
            Ioc.Get<ShellCore>()?.Stop();
        }
    }
}